home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 November: Tool Chest / Dev.CD Nov 00 TC Disk 1.toast / Tool Chest / Toolbox / GetHelpStrings / acur.c next >
Encoding:
C/C++ Source or Header  |  1995-10-20  |  3.4 KB  |  170 lines  |  [TEXT/CWIE]

  1. /*
  2. Enclosed is a complete subroutine package to animate your cursors using
  3. acurs resources.
  4. I am the author.
  5.  
  6. -- David Phillip Oster - Note new address. Old one has gone Bye Bye.
  7. -- oster@well.sf.ca.us = {backbone}!well!oster
  8.  
  9. Modified to support color cursors by Brian Bechtel, blob@apple.com
  10. */
  11.  
  12. #include "acur.h"
  13.  
  14. /*
  15.     CursorList - these resources define the black and white animated 
  16.     cursor data structure
  17.  */
  18. typedef union UHand 
  19. {
  20.         CursHandle h;
  21.         struct 
  22.         {
  23.                 short i;
  24.                 short fill;
  25.         } i;
  26. } UHand;
  27.  
  28. typedef struct CursorList 
  29. {
  30.         short cnt;
  31.         short current;
  32.         UHand curs[1];
  33. } CursorList, *CursorPList, **CursorHList;
  34.  
  35.  
  36. /*
  37.     CursorList - these resources define the color animated cursor 
  38.     data structure
  39.  */
  40. typedef union UCHand 
  41. {
  42.         CCrsrHandle h;
  43.         struct 
  44.         {
  45.                 short i;
  46.                 short fill;
  47.         } i;
  48. } UCHand;
  49.  
  50. typedef struct CCursorList 
  51. {
  52.         short cnt;
  53.         short current;
  54.         UCHand curs[1];
  55. } CCursorList, *CCursorPList, **CCursorHList;
  56.  
  57.  
  58. /* globals 
  59.  */
  60. static CursorHList    acurs = nil;            /* used in SpinBWCursor */
  61. static CCursorHList    cacurs = nil;            /* used in SpinColorCursor */
  62. static SysEnvRec    theWorld;
  63.     
  64.  
  65.  
  66. static void InitColorCursors(void);
  67. static void InitBWCursors(void);
  68. static void SpinColorCursor(short delta);
  69. static void SpinBWCursor(short delta);
  70.  
  71.  
  72. void InitCursors()
  73. {
  74.     SysEnvirons(curSysEnvVers, &theWorld);
  75.     if (theWorld.hasColorQD)
  76.         InitColorCursors();
  77.     else
  78.         InitBWCursors();
  79. }
  80. /* InitColorCursors - initialize our color anuimated cursor structure
  81.  */
  82. void InitColorCursors()
  83. {
  84.     CCrsrHandle h;
  85.     short i;
  86.     
  87.     if (nil != (cacurs = (CCursorHList) GetResource('acur', 0) ) )
  88.     {
  89.         for(i = 0; i < (**cacurs).cnt; i++)
  90.         {
  91.             h = (CCrsrHandle) GetCCursor((**cacurs).curs[i].i.i);
  92.             MoveHHi((Handle) h);
  93.             HLock((Handle) h);
  94.             (**cacurs).curs[i].h = h;
  95.         }
  96.     }
  97. }
  98.  
  99. /* InitBWCursors - initialize our black and white anuimated cursor structure
  100.  */
  101. void InitBWCursors()
  102. {
  103.     CursHandle h;
  104.     short i;
  105.     
  106.     if (nil != (acurs = (CursorHList) GetResource('acur', 0) ) )
  107.     {
  108.         for(i = 0; i < (**acurs).cnt; i++)
  109.         {
  110.             h = (CursHandle) GetCursor((**acurs).curs[i].i.i);
  111.             MoveHHi((Handle) h);
  112.             HLock((Handle) h);
  113.             (**acurs).curs[i].h = h;
  114.         }
  115.     }
  116. }
  117.  
  118. /* SpinCursor - transit the cursor to the next in the series.
  119.         delta should be 1 to go forward,
  120.         -1 to go backward
  121.  */
  122. void SpinCursor(short delta)
  123. {
  124.     if (theWorld.hasColorQD)
  125.         SpinColorCursor(delta);
  126.     else
  127.         SpinBWCursor(delta);
  128. }
  129.  
  130. /* SpinColorCursor - transit the cursor to the next in the series.
  131.         delta should be 1 to go forward,
  132.         -1 to go backward
  133.  */
  134. void SpinColorCursor(short delta)
  135. {
  136.     short c;
  137.     
  138.     if(cacurs != nil){
  139.             c = (**cacurs).current + delta;
  140.             if(c >= (**cacurs).cnt){
  141.                     c = 0;
  142.             }else if(c < 0){
  143.                     c = (**cacurs).cnt-1;
  144.             }
  145.             (**cacurs).current = c;
  146.             SetCCursor( ((**cacurs).curs[c].h) );
  147.     }
  148. }
  149.  
  150. /* SpinBWCursor - transit the cursor to the next in the series.
  151.         delta should be 1 to go forward,
  152.         -1 to go backward
  153.  */
  154. void SpinBWCursor(short delta)
  155. {
  156.     short c;
  157.     
  158.     if(acurs != nil){
  159.             c = (**acurs).current + delta;
  160.             if(c >= (**acurs).cnt){
  161.                     c = 0;
  162.             }else if(c < 0){
  163.                     c = (**acurs).cnt-1;
  164.             }
  165.             (**acurs).current = c;
  166.             SetCursor( *((**acurs).curs[c].h) );
  167.     }
  168. }
  169.  
  170.